function x_fit = BB98d_fit_parameters(T_a,dT_a_dt,T_o,l_use_loss,P)

    options_ols = optimoptions('fmincon','Algorithm','interior-point',...
                               'MaxFunctionEvaluations',10000,'Display','off');
    if P.do_season == 0
        x0     = [   20    10 .5]';
        LB     = [0.001 0.001  0]';
        x_fit  = fmincon(@(x) BB98d_loss_time_domain(x,T_a,dT_a_dt,T_o,l_use_loss,P),x0,[],[],[],[],LB,[],[],options_ols);

    elseif P.do_season == 1
        
        x0     = [   20    10    0.5     .5    pi/3     .5    pi/3     .5    pi/3]';
        LB     = [0.001 0.001      0 0.0001 -100*pi 0.0001 -100*pi 0.0001 -100*pi]';
        UB     = [10000 10000  10000 0.9999  100*pi 0.9999  100*pi 0.9999  100*pi]';

        x_fit  = fmincon(@(x) BB98d_loss_time_domain(x,T_a,dT_a_dt,T_o,l_use_loss,P),x0,[],[],[],[],LB,UB,[],options_ols);
    end
end
